﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Http;
using System.Xml;
using fqlmoney.Common;
using fqlmoney.Model;
using fqlmoney.BLL;

namespace fqlmoney.Controllers
{
    public class LoginController : Controller
    {

        /// <summary>
        /// 跳转到qq授权页面
        /// </summary>
        /// <returns></returns>
        public ActionResult Index()
        {
            return View();
        }
        [HttpPost]
        public ActionResult Submit()
        {
            string loginname = Request.Form["loginname"];
            string pwd = Request.Form["loginpwd"];
            UserInfoBLL bll = new UserInfoBLL();
            userinfo model = bll.GetUserInfoByLoginName(loginname);
            ViewBag.Msg = "";
            if (model == null)
            {
                ViewBag.Msg = "账号不存在！";
                Response.Cookies.Delete("fqlmoneyuser");
            }
            else if(model.u_loginpwd!=Utils.MD5(pwd))
            {
                ViewBag.Msg = "密码不正确！";
                Response.Cookies.Delete("fqlmoneyuser");
            }
            else if(model.u_loginpwd == Utils.MD5(pwd))
            {
                HttpContext.Session.SetString("fqlmoneyuser", JSONHelper.SerializeObject(model));
                Response.Cookies.Append("fqlmoneyuser", Utils.AESEncrypt(loginname), new CookieOptions { Path = "/", Expires = DateTime.Now.AddMonths(1) });
                Response.Redirect("/Home/Index");
            }
            return View();
        }

    }
}